﻿using System;
using System.Configuration;
using System.Diagnostics;

using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;

namespace BizElements.BusinessLayer
{
    /// <summary>
    /// Configuration object for a <see cref="FormattedWebServiceTraceListener"/>.
    /// </summary>
    [Assembler(typeof(FormattedWebServiceTraceListenerAssembler))]
    internal class FormattedWebServiceTraceListenerData : TraceListenerData
    {
        #region Constants.

        private const string urlProperty = "url";
        private const string formatterNameProperty = "formatter";
        private const string senderAssemblyProperty = "senderAssembly";
        private const string senderClassProperty = "senderClass";

        #endregion

        #region Constructors.

        /// <summary>
        /// Initializes a <see cref="FormattedWebServiceTraceListenerData"/>.
        /// </summary>
        public FormattedWebServiceTraceListenerData()
        {
        }

        /// <summary>
        /// Initializes a named instance of <see cref="FormattedWebServiceTraceListenerData"/> with 
        /// name, stored procedure name, databse instance name, and formatter name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="formatterName">The formatter name.</param>        
        public FormattedWebServiceTraceListenerData(string name, string formatterName)
            : this(name, formatterName, TraceOptions.None)
        {
        }

        /// <summary>
        /// Initializes a named instance of <see cref="FormattedWebServiceTraceListenerData"/> with 
        /// name, stored procedure name, databse instance name, and formatter name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="formatterName">The formatter name.</param>
        /// <param name="traceOutputOptions">The trace options.</param>
        public FormattedWebServiceTraceListenerData(string name, string formatterName, TraceOptions traceOutputOptions)
            : base(name, typeof(FormattedWebServiceTraceListener), traceOutputOptions)
        {
            this.Formatter = formatterName;
        }

        #endregion

        #region Properties.

        /// <summary>Gets and sets URL of the <b>WsLogReceiver.asmx</b> Web service.</summary>
        [ConfigurationProperty(urlProperty, IsRequired = false)]
        public string Url
        {
            get { return (string)base[urlProperty]; }
            set { base[urlProperty] = value; }
        }

        /// <summary>Gets and sets the formatter name.</summary>
        [ConfigurationProperty(formatterNameProperty, IsRequired = false)]
        public string Formatter
        {
            get { return (string)base[formatterNameProperty]; }
            set { base[formatterNameProperty] = value; }
        }

        /// <summary>Gets or sets the assembly that contains a class that implements <see cref="ILogSender"/> interface which is used to send data to service.</summary>
        [ConfigurationProperty(senderAssemblyProperty, IsRequired = false)]
        public string SenderAssembly
        {
            get { return (string)base[senderAssemblyProperty]; }
            set { base[senderAssemblyProperty] = value; }
        }

        /// <summary>Gets or sets the name of a class that implements <see cref="ILogSender"/> interface which is used to send data to service.</summary>
        [ConfigurationProperty(senderClassProperty, IsRequired = false)]
        public string SenderClass
        {
            get { return (string)base[senderClassProperty]; }
            set { base[senderClassProperty] = value; }
        }

        #endregion
    }
}